<?php
/**
 * Created by PhpStorm.
 * User: LiuJiaJun
 * Date: 2019/1/21
 * Time: 11:10
 */

namespace api\storage\model;


use think\Model;

class CarSeatModel extends Model
{
    protected $table = 'iwh_car_seat';
    protected $pk = 'uuid';

    /**
     * 清除 carSeat 里的内容
     *
     * @param $carUuid
     * @return false|int
     */
    public function cleanCarSeat($carUuid){
        $where['car_uuid'] = $carUuid;
        $saveData['sub_materiel_id'] = '';
        $saveData['reel_id'] = '';
        $saveData['count'] = 0;
        $saveData['is_used'] = 0;
        return $this->isUpdate(true)->save($saveData,$where);
    }

    /**
     * 查找seat_code
     *
     * @param $carUuid
     * @param $type
     * @return mixed
     */
    public function findNotUsedSeatCode($carUuid,$type){
        $where['car_uuid'] = $carUuid;
        $where['seat_type'] = $type;
        $where['is_used'] = 0;
        return $this->where($where)->order('seat_code')->value('seat_code');
    }

    /**
     * 更新占用仓库字段
     *
     * @param $carUuid
     * @param $seatCode
     * @return false|int
     */
    public function updateIsUsed($carUuid,$seatCode){
        $where['car_uuid'] = $carUuid;
        $where['seat_code'] = $seatCode;
        $data['is_used'] = 1;
        return $this->isUpdate(true)->save($data,$where);
    }

    /**
     * 更新站位信息
     *
     * @param $carUuid
     * @param $seatCode
     * @param $data
     * @return false|int
     */
    public function updateSeat($carUuid,$seatCode,$data){
        $where['car_uuid'] = $carUuid;
        $where['seat_code'] = $seatCode;
        return $this->isUpdate(true)->save($data,$where);
    }

    /**
     * 更新站位命令码
     *
     * @param $seatCode
     * @param $carUuid
     * @param $commandCode
     * @return false|int
     */
    public function updateCommandCode($seatCode,$carUuid,$commandCode){
        $data['command_code'] = $commandCode;
        $where['seat_code'] = $seatCode;
        $where['car_uuid'] = $carUuid;
        return $this->isUpdate(true)->save($data,$where);
    }
}